<template>
  <view>
    <view class="xmain">
      <headBar title="错题收集列表"></headBar>
    </view>
    <view class="qtListBox">
      <view v-if="Object.keys(list).length">
        <view v-for="(item,index) in list">
          <view class="qtListLine">
            <view v-if="item.img_url">
              <view class="uni-flex uni-row">
                <view class="flex-item">
                  <image :src="item.img_url" class="qtListLineImage"></image>
                </view>
                <view class="flex-item">
                  <view >{{item.title}}</view>
                </view>
              </view>
            </view>
            <view v-else>
              <view class="qtListLineText" @click="x_redirect('/pages/wrong/wrong?id='+item.question_id)">
                {{ item.title }}
              </view>
            </view>
            <view>
                <view class="qtListLineAction">
                  <view class="uni-flex uni-row">
                    <uni-fav @click="x_redirect('/pages/wrong/wrong?id='+item.question_id)" class="favBtn flex-item" :star="false" bg-color="#3495fc" fg-color="#ffffff"
                             :contentText="{contentDefault: '查看详情',contentFav: '查看详情'}" :circle="true"/>
                    <view style="width:20rpx;"></view>
                    <uni-fav @click="delItem(index)" class="favBtn flex-item" :star="false" bg-color="#dd524d" fg-color="#ffffff"
                             bg-color-checked="#007aff"  :contentText="{contentDefault: '移除',contentFav: '移除'}" :circle="true"/>
                  </view>
                </view>
            </view>
          </view>
        </view>
      </view>
      <view v-else>
        <view class="qtListNo">暂无收藏数据</view>
      </view>
      <view class="xnotice" v-if="alertShow">
        <view class="xnoticeMask"></view>
        <view class="qtWrongNotice">
          <view></view>
          <uni-section title="确定要把该题从错题收集列表中移除吗？" type="line">
          </uni-section>
          <view style="min-height: 100rpx;"></view>
          <view>
            <view class="uni-flex uni-row">
              <view class="flex-item xnoticeAction">
                <view class="xk_btn" @click="alertShow = false">取消</view>
              </view>
              <view class="flex-item xnoticeAction"></view>
              <view class="flex-item xnoticeAction">
                <view class="xk_btn xk_btn_active" @click="doDelItem()">确定</view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <bootNav nav="home"></bootNav>
  </view>

</template>

<script>
export default {
  data() {
    return {
      list: {},
      listKey:'qtWrongList',
      alertShow:false,
      delId:0
    }
  },
  onShareAppMessage() {
    return {
      title: this.title,
    }
  },
  onShareTimeline: function () {
    return {
      title: this.title,
    }
  },
  onLoad() {
    var t = this;
    t.setList();
  },
  methods: {
    setList() {
      var t = this;
      var lst = t.xCacheGet(t.listKey);
      var combineLst = {};
      if (lst) {
        for(var x in lst){
          var item = lst[x];
          var title = item.title;
          item.title = title.substring(0, 50)+"...";
          combineLst[x] = item;
        }
        t.list = combineLst;
      }
    },
    delItem(id){
      var t = this;
      t.delId = id;
      t.alertShow = true;

    },
    doDelItem(){
      var t =this;
      var questionList = t.xCacheGet(t.listKey);
      if(questionList[t.delId]){
        delete questionList[t.delId];
        t.xCacheSet(t.listKey,questionList);
      }
      t.x_redirect('/pages/wrong/lst')
    }
  }
}
</script>

<style>
@import "../question/question.css";

</style>
